#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#include<conio.h>
#include "mastructure.h"
#include <windows.h>
#include<wincon.h>


void color_console(WORD text_color, WORD bg_color)
{
    HANDLE console_h=GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleTextAttribute(console_h, text_color|bg_color*16);
}


void change_cursor(unsigned size, unsigned visibility)
{
    HANDLE console_h;
    CONSOLE_CURSOR_INFO cci;
    console_h=GetStdHandle(STD_OUTPUT_HANDLE);
    cci.dwSize=size;
    cci.bVisible=visibility;
    SetConsoleCursorInfo(console_h, &cci);
}


void move_cursor(unsigned x, unsigned y)
{
    HANDLE console_h;
    COORD position;
    console_h=GetStdHandle(STD_OUTPUT_HANDLE);
    position.X=x;
    position.Y=y;
    SetConsoleCursorPosition(console_h, position);
}


int cursor_x()
{
    HANDLE console_h;
    CONSOLE_SCREEN_BUFFER_INFO csbi;
    console_h=GetStdHandle(STD_OUTPUT_HANDLE);
    GetConsoleScreenBufferInfo(console_h, &csbi);
    return csbi.dwCursorPosition.X;
}


int cursor_y()
{
    HANDLE console_h;
    CONSOLE_SCREEN_BUFFER_INFO csbi;
    console_h=GetStdHandle(STD_OUTPUT_HANDLE);
    GetConsoleScreenBufferInfo(console_h, &csbi);
    return csbi.dwCursorPosition.Y;
}


void signaler_rubrique_choisie()
{
    int i;
    for( i=1000; i<10001; i+=1000)
    _beep(i, 12);

}


void animer_description()
{
	int i=0;
    char salut[]="WELCOME TO KAKURO WORLD";
    move_cursor(24, 3);
    change_cursor(100, 1);
    color_console(1,0);
    for(i=0; i<23; i++)
    {
        _sleep(100);
        printf("%c", salut[i]);
    }
    change_cursor(100, 0);
    move_cursor(24, 3);
    color_console(13, 0);
    for(i=0; i<23; i++)
    {
        _sleep(20);
        printf("%c", salut[i]);
    }
}

void animer_clique_terminer()
{
	int i=0;
    char texte[]="R E T O U R :  E N T R E E ";
    move_cursor(24,3);
    change_cursor(100, 1);
    color_console(13,0);
    for(i=0; i<36; i++)
    {
        _sleep(100);
        printf("%c", texte[i]);
    }
    change_cursor(100, 0);
    move_cursor(24, 3);
    color_console(13, 0);
    for(i=0; i<49; i++)
    {
        _sleep(20);
        printf("%c", texte[i]);
    }
}





int afficher_titre()
{
    FILE *p_fichier=NULL;
    char ch_lu[62]="", i=0;
    p_fichier=fopen("./mini_projet/titre.txt", "r");
    if(p_fichier)
    {
        color_console(5, 0);
        while(fgets(ch_lu, 62, p_fichier))
        {
            move_cursor(8, 16+i);
            printf("%s", ch_lu);
            i++;
        }
        i=0;
        fclose(p_fichier);
        color_console(5,0);
    }
    else return 1;
    return 0;
}


int afficher_texte_fichier(char *fichier)
{
    FILE *p_fichier=NULL;
    char ch_lu[62]="", i=0;
    p_fichier=fopen(fichier, "r");
    if(p_fichier)
    {
        color_console(15, 0);
        while(fgets(ch_lu, 62, p_fichier))
        {
            move_cursor(19, 13+i);
            printf("%s", ch_lu);
            i++;
        }
        i=0;
        fclose(p_fichier);
        color_console(15,0);
    }
    else return 1;
    return 0;
}
